<html>
<head><meta charset="utf-8"><title>Testing memory allocation · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Testing.20memory.20allocation.html">Testing memory allocation</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216544817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Testing%20memory%20allocation/near/216544817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Testing.20memory.20allocation.html#216544817">(Nov 12 2020 at 23:34)</a>:</h4>
<p>I have some types which make raw alloc/free calls. I'm looking for a way to #[test] these types: for example, to check that when one is dropped "free" is called appropriately. Is there any way to do that?</p>



<a name="216549396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Testing%20memory%20allocation/near/216549396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Testing.20memory.20allocation.html#216549396">(Nov 13 2020 at 00:25)</a>:</h4>
<p>could you use a custom allocator that tracks when alloc/free calls happen?</p>



<a name="216556146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Testing%20memory%20allocation/near/216556146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Testing.20memory.20allocation.html#216556146">(Nov 13 2020 at 01:44)</a>:</h4>
<p>That's what I'm going with, the problem I have now is that I need TLS to record the details, but <code>thread_local!</code> itself allocates</p>



<a name="216556251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Testing%20memory%20allocation/near/216556251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Testing.20memory.20allocation.html#216556251">(Nov 13 2020 at 01:44)</a>:</h4>
<p>and I don't know how to prevent the allocator recursively calling itself...</p>



<a name="216556303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Testing%20memory%20allocation/near/216556303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Testing.20memory.20allocation.html#216556303">(Nov 13 2020 at 01:44)</a>:</h4>
<p>since storing that flags itself would require TLS...</p>



<a name="216557588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Testing%20memory%20allocation/near/216557588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Testing.20memory.20allocation.html#216557588">(Nov 13 2020 at 01:57)</a>:</h4>
<p>Is there a reason you can't just use atomics directly?</p>



<a name="216557598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Testing%20memory%20allocation/near/216557598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Testing.20memory.20allocation.html#216557598">(Nov 13 2020 at 01:57)</a>:</h4>
<p>e.g. <code>static ALLOC_COUNT: AtomicUsize = AtomicUsize::new(0);</code></p>



<a name="216558145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Testing%20memory%20allocation/near/216558145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Testing.20memory.20allocation.html#216558145">(Nov 13 2020 at 02:06)</a>:</h4>
<p>I want a per-thread count</p>



<a name="216558228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Testing%20memory%20allocation/near/216558228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Testing.20memory.20allocation.html#216558228">(Nov 13 2020 at 02:07)</a>:</h4>
<p>I figured out the problem anyway - it wasn't thread_local! allocating, it was a case where I accidentally used * instead of wrapping_mul, which resulted in a panic, and that's what was allocating, which then caused an ILLEGAL_INSTRUCTION error which masked the original panic...</p>



<a name="216558449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Testing%20memory%20allocation/near/216558449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Testing.20memory.20allocation.html#216558449">(Nov 13 2020 at 02:11)</a>:</h4>
<p>ah ok</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>